<?php

class DBQueryResult
{
    /**
     *
     * @var mysqli_result
     */
    private $queryResult;
    
    public function __construct( $queryResult )
    {
        $this->queryResult = $queryResult;
    }
    
    public function Count()
    {
        if ( $this->queryResult )
        {
            return $this->queryResult->num_rows;
        }
        return 0;
    }

    public function GetObject()
    {
        if ( $this->queryResult )
        {
            return $this->queryResult->fetch_object();
        }
        return null;
    }

    public function GetArray()
    {
        if ( $this->queryResult )
        {
            return $this->queryResult->fetch_array();
        }
        return null;
    }

    public function GetAssoc()
    {
        if ( $this->queryResult )
        {
            $res = $this->queryResult->fetch_assoc();
            return $res ? new ArrayObject($res) : $res;
        }
        return null;
    }

    public function GetAllAssoc()
    {
        $res = array();
        while ( $r = $this->GetAssoc() )
        {
            array_push( $res, $r );
        }
        return $res;
    }

    public function Seek( int $rowNum )
    {
        return $this->queryResult->data_seek( $rowNum );
    }

    public function Free()
    {
        $this->queryResult->free_result();
    }
}

?>
